Namespacing everything to /UVa.
[and.git] / UVa / 11660 - Look-and-Say sequences / 11660.cpp
blob174e8ccfa56e1d04aa0e7da3ef73217e4259f3b2
1 using namespace std;
2 #include <algorithm>
3 #include <iostream>
4 #include <iterator>
5 #include <numeric>
6 #include <sstream>
7 #include <fstream>
8 #include <cassert>
9 #include <climits>
10 #include <cstdlib>
11 #include <cstring>
12 #include <string>
13 #include <cstdio>
14 #include <vector>
15 #include <cmath>
16 #include <queue>
17 #include <deque>
18 #include <stack>
19 #include <list>
20 #include <map>
21 #include <set>
23 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
24 #define For(i, a, b) for (int i=(a); i<(b); ++i)
25 #define D(x) cout << #x " is " << x << endl
27 int main(){
28 int x1, times, position;
29 while (cin >> x1 >> times >> position) {
30 if (x1 == 0 and times == 0 and position == 0) break;
31 vector< int > v;
32 while (x1 > 0) v.push_back(x1 % 10), x1 /= 10;
33 reverse(v.begin(), v.end());
35 //printf("V is "); For(i, 0, v.size()) printf("%d ", v[i]); puts("");
37 for (int t = 0; t < times - 1; ++t) {
38 vector< int > w;
40 for (int i = 0; i < v.size(); ) {
41 int j = i;
42 while (j < v.size() and v[i] == v[j]) j++;
43 int size = j - i;
44 //printf("%d appears %d times from [%d,%d)\n", v[i], size, i, j);
45 int n = w.size();
46 while (size > 0) w.push_back(size % 10), size /= 10;
47 reverse(w.begin() + n, w.end());
48 w.push_back(v[i]);
50 if (w.size() > 3000) break;
51 i = j;
54 v = w;
55 //printf("V is "); For(i, 0, v.size()) printf("%d ", v[i]); puts("");
57 cout << v[position - 1] << endl;
59 return 0;